package com.carcenter.pojo;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 	* A data access object (DAO) providing persistence and search support for CarMaintain entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see com.carcenter.pojo.CarMaintain
  * @author MyEclipse Persistence Tools 
 */

public class CarMaintainDAO extends BaseHibernateDAO  {
	     private static final Logger log = LoggerFactory.getLogger(CarMaintainDAO.class);
		//property constants
	public static final String BRAND = "brand";
	public static final String OIL_A = "oilA";
	public static final String LV_A = "lvA";
	public static final String FIRE_A = "fireA";
	public static final String OIL_B = "oilB";
	public static final String LV_B = "lvB";
	public static final String FIRE_B = "fireB";
	public static final String OIL_C = "oilC";
	public static final String LV_C = "lvC";
	public static final String FIRE_C = "fireC";
	public static final String OIL_PRICE = "oilPrice";
	public static final String LV_PRICE = "lvPrice";
	public static final String FIRE_PRICE = "firePrice";



    
    public void save(CarMaintain transientInstance) {
        log.debug("saving CarMaintain instance");
        try {
            getSession().save(transientInstance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }
    
	public void delete(CarMaintain persistentInstance) {
        log.debug("deleting CarMaintain instance");
        try {
            getSession().delete(persistentInstance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }
    
    public CarMaintain findById( java.lang.Integer id) {
        log.debug("getting CarMaintain instance with id: " + id);
        try {
            CarMaintain instance = (CarMaintain) getSession()
                    .get("com.carcenter.pojo.CarMaintain", id);
            return instance;
        } catch (RuntimeException re) {
            log.error("get failed", re);
            throw re;
        }
    }
    
    
    public List findByExample(CarMaintain instance) {
        log.debug("finding CarMaintain instance by example");
        try {
            List results = getSession()
                    .createCriteria("com.carcenter.pojo.CarMaintain")
                    .add(Example.create(instance))
            .list();
            log.debug("find by example successful, result size: " + results.size());
            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }    
    
    public List findByProperty(String propertyName, Object value) {
      log.debug("finding CarMaintain instance with property: " + propertyName
            + ", value: " + value);
      try {
         String queryString = "from CarMaintain as model where model." 
         						+ propertyName + "= ?";
         Query queryObject = getSession().createQuery(queryString);
		 queryObject.setParameter(0, value);
		 return queryObject.list();
      } catch (RuntimeException re) {
         log.error("find by property name failed", re);
         throw re;
      }
	}

	public List findByBrand(Object brand
	) {
		return findByProperty(BRAND, brand
		);
	}
	
	public List findByOilA(Object oilA
	) {
		return findByProperty(OIL_A, oilA
		);
	}
	
	public List findByLvA(Object lvA
	) {
		return findByProperty(LV_A, lvA
		);
	}
	
	public List findByFireA(Object fireA
	) {
		return findByProperty(FIRE_A, fireA
		);
	}
	
	public List findByOilB(Object oilB
	) {
		return findByProperty(OIL_B, oilB
		);
	}
	
	public List findByLvB(Object lvB
	) {
		return findByProperty(LV_B, lvB
		);
	}
	
	public List findByFireB(Object fireB
	) {
		return findByProperty(FIRE_B, fireB
		);
	}
	
	public List findByOilC(Object oilC
	) {
		return findByProperty(OIL_C, oilC
		);
	}
	
	public List findByLvC(Object lvC
	) {
		return findByProperty(LV_C, lvC
		);
	}
	
	public List findByFireC(Object fireC
	) {
		return findByProperty(FIRE_C, fireC
		);
	}
	
	public List findByOilPrice(Object oilPrice
	) {
		return findByProperty(OIL_PRICE, oilPrice
		);
	}
	
	public List findByLvPrice(Object lvPrice
	) {
		return findByProperty(LV_PRICE, lvPrice
		);
	}
	
	public List findByFirePrice(Object firePrice
	) {
		return findByProperty(FIRE_PRICE, firePrice
		);
	}
	

	public List findAll() {
		log.debug("finding all CarMaintain instances");
		try {
			String queryString = "from CarMaintain";
	         Query queryObject = getSession().createQuery(queryString);
			 return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}
	
    public CarMaintain merge(CarMaintain detachedInstance) {
        log.debug("merging CarMaintain instance");
        try {
            CarMaintain result = (CarMaintain) getSession()
                    .merge(detachedInstance);
            log.debug("merge successful");
            return result;
        } catch (RuntimeException re) {
            log.error("merge failed", re);
            throw re;
        }
    }

    public void attachDirty(CarMaintain instance) {
        log.debug("attaching dirty CarMaintain instance");
        try {
            getSession().saveOrUpdate(instance);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
    
    public void attachClean(CarMaintain instance) {
        log.debug("attaching clean CarMaintain instance");
        try {
            getSession().lock(instance, LockMode.NONE);
            log.debug("attach successful");
        } catch (RuntimeException re) {
            log.error("attach failed", re);
            throw re;
        }
    }
}